package sz.szsmk.citizencard.mvp.presenter;

import android.util.Log;

import com.facebook.stetho.common.LogUtil;
import com.google.gson.Gson;
import com.lidroid.xutils.util.LogUtils;

import javax.inject.Inject;

import sz.szsmk.citizencard.model.network.GsdxNetApi;
import sz.szsmk.citizencard.model.network.bean.request.QueryCollectedStandreq;
import sz.szsmk.citizencard.model.network.bean.request.QueryInvoiceOpensReq;
import sz.szsmk.citizencard.model.network.bean.response.QueryInvoiceOpensRes;
import sz.szsmk.citizencard.model.network.bean.response.QueryNearStandbyRes;
import sz.szsmk.citizencard.mvp.contract.IBusSiteCollectContact;
import sz.szsmk.citizencard.mvp.contract.ICardListTicketsContact;
import sz.szsmk.citizencard.retrofitrxjava.ErrorAction;
import sz.szsmk.citizencard.retrofitrxjava.NetworkDateSources;
import sz.szsmk.citizencard.retrofitrxjava.SubscribeResult;

/**
 * Copyright (c)2018
 * author: zdh
 * created on: 2018/11/15 9:52
 * description:
 */
public class CardsListTicketsPresenter extends IBasePresenter
implements ICardListTicketsContact.ICardListTicketsPresenter<ICardListTicketsContact.ICardListTicketsView> {


    private NetworkDateSources mNetworkDateSource;
    GsdxNetApi gsdxNetApi;

    @Inject
    public CardsListTicketsPresenter(GsdxNetApi gsdxNetApi) {
        this.gsdxNetApi = gsdxNetApi;

        this.mNetworkDateSource = NetworkDateSources.getInstance();
    }

    @Override
    public void getDataList(String pageIndex, String PageSize) {


        QueryInvoiceOpensReq queryInvoiceOpensReq=new QueryInvoiceOpensReq();
        queryInvoiceOpensReq.setPageIndex(pageIndex);
        queryInvoiceOpensReq.setPageSize(PageSize);
        Log.d("clark",new Gson().toJson(queryInvoiceOpensReq));
        mNetworkDateSource.queryInvoiceOpens(queryInvoiceOpensReq, new SubscribeResult<QueryInvoiceOpensRes>() {
                    @Override
                    protected void onOk(QueryInvoiceOpensRes response) {
                        ((ICardListTicketsContact.ICardListTicketsView)mView).getDataListSucc(response);

                    }

                    @Override
                    protected void onFailure(QueryInvoiceOpensRes res){
                        super.onFailure(res);
                        ((ICardListTicketsContact.ICardListTicketsView)mView).getDataListFail();
                    }

                    @Override
                    protected  void onNext(QueryInvoiceOpensRes res){
                        super.onNext(res);
                        ((ICardListTicketsContact.ICardListTicketsView)mView).getDataListFail();
                    }

                }, new ErrorAction() {
                    @Override
                    public void onCall(Throwable throwable) {
                        ((ICardListTicketsContact.ICardListTicketsView)mView).getDataListFail();
                    }
                });


    }

}
